﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CrayonsBox
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : MahApps.Metro.Controls.MetroWindow
    {
        public static MainWindow Instance { get; set; }
        public SpriteEditor spriteEditor;
        public WrapPanel nap;

        public MainWindow()
        {
            InitializeComponent();

            MainWindow.Instance = this;
            spriteEditor = new SpriteEditor();

            nap = new WrapPanel();
            nap.Background = new SolidColorBrush(Color.FromRgb(0, 255, 0));

            TransitioningMainContent.Content = spriteEditor;
        }

        private void SpriteEditor_Click(object sender, RoutedEventArgs e)
        {
            TransitioningMainContent.Content = spriteEditor;
        }

        private void LevelEditor_Click(object sender, RoutedEventArgs e)
        {
            TransitioningMainContent.Content = nap;
        }

        public void ToggleFlyout(int index)
        {
            var flyout = this.Flyouts.Items[index] as MahApps.Metro.Controls.Flyout;
            if (flyout == null)
            {
                return;
            }

            flyout.IsOpen = !flyout.IsOpen;
        }

        private void btnInFrameModule_DoubleClick(object sender, MouseButtonEventArgs e)
        {
            spriteEditor.btnInFrameModule_DoubleClick(sender, e);
        }

        private void Button_MouseEnter(object sender, MouseEventArgs e)
        {
            if (!imgPopup.IsOpen) { imgPopup.IsOpen = true; }

            Image bmSrc = new Image();
            DataModel.Sprite.Module m = (DataModel.Sprite.Module)(sender as Button).Tag;
            bmSrc.Source = m.BmpSource;
            imgPopup.Child = bmSrc;
        }

        private void Button_MouseMove(object sender, MouseEventArgs e)
        {
            Point currentPosition = e.GetPosition(lsFrameModule);
            imgPopup.HorizontalOffset = currentPosition.X + 20;
            imgPopup.VerticalOffset = currentPosition.Y;
        }

        private void Button_MouseLeave(object sender, MouseEventArgs e)
        {
            imgPopup.IsOpen = false;
        }



    }
}
